<?php
	// Si le fichier de qui d�finie les constantes n'a pas encore �t� appel� on le charge
	if( !defined( 'CONFIGURATION_FILE_LOADED'))
		include( $_SERVER['DOCUMENT_ROOT'].'/'.URL_SITE.'/includes/configuration_include.php');
	
	include( PATH_MODELS.'admin_user_model.php');
	include( PATH_VIEWS.'admin_user_view.php');
        include( PATH_MODELS.'db_connexion_model.php');
	
	$bdd= model_db_connexion();
	
	$str= "";
	
	// Si l'utilisateur est d�j� logu�
	if(!empty($_SESSION['id_user']) && model_is_root( $bdd, $_SESSION['id_user']))
	{
		if( isset( $_GET['set_admin']) && $_GET['set_admin']>=0)
		{
			model_set_admin( $bdd, $_SESSION['id_user'], $_GET['set_admin']);
			header( 'location:' . URL_ROOT . 'config-utilisateurs');
		}
		else if( isset( $_GET['set_normal']) && $_GET['set_normal']>=0)
		{
			model_set_normal( $bdd, $_SESSION['id_user'], $_GET['set_normal']);
			header( 'location:' . URL_ROOT . 'config-utilisateurs');
		}
		else if( isset( $_GET['delete']) && $_GET['delete']>=0)
		{
			model_delete_user( $bdd, $_SESSION['id_user'], $_GET['delete']);
			header( 'location:' . URL_ROOT . 'config-utilisateurs');
		}
		
		// On r�cup�re les �v�nements qui n'ont pas �t� valid�s
		$users_informations= model_users_config_informations( $bdd);
		
		$str.= ($users_informations!= null) ? view_users_informations( $users_informations) : view_no_more_users_left();
	}
	else
	{
		$str.=  view_not_logued_as_admin();
	}
?>
<?php
      
	echo $str."\n";
        
?>